//
//  PORegexTool.m
//  PO_Chat
//
//  Created by -- on 2020/1/14.
//  Copyright © 2020 舒杨. All rights reserved.
//

#import "PORegexTool.h"

@implementation PORegexTool

#pragma 控制只输入数字
+ (BOOL)checkInputOnlyNumber : (NSString *) string {
    if (string.length < 1) {
        return YES;
    }
    unichar character = [string characterAtIndex:string.length-1];
    if (character > 47 && character < 58)
        return YES;
    return NO;
}

#pragma 检测第一个输入的字符是否是小数点
+ (BOOL)checkInputFristPoint : (NSString *) string {
    //前面数字.
    NSString *regex1 = @"^[.]*";
    NSPredicate *pre1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex1];
    BOOL isP = [pre1 evaluateWithObject:string];
    return isP;
}

#pragma 控制只输入.和数字
+ (BOOL)checkInputOnlyPointNumber : (NSString *) string {
    if (string.length < 1) {
        return YES;
    }
    unichar character = [string characterAtIndex:string.length-1];
    if (character > 47 && character < 58)
        return YES;
    if (character == 46) return YES;
    return NO;
}

#pragma 检测小数点后面是否满2位
+ (BOOL)checkAfterPointLenth: (NSString *) string {
    if([string rangeOfString:@"."].location !=NSNotFound) {
        NSRange ran = [string rangeOfString:@"."];
        NSInteger count = string.length - ran.location;
        if (count <= 3) {
            return NO;
        }
        return YES;
    }else {
        return NO;
    }
}



@end
